package basic.thread.again;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Lock
 *
 * @author bingo
 * @create 2018-02-24 19:55
 **/
public class Squence3 {

    private int value=0;

    Lock lock = new ReentrantLock();

    public  int getValue(){

        lock.lock();
        int i=value++;
        System.out.print("a");
        b();
        lock.unlock();
        return  i;
    }

    public void b(){
        lock.lock();
        System.out.println(",b");
        lock.unlock();
    }

    public static void main(String[] args) {

            Squence3 sequence3 = new Squence3();

            new Thread(new Runnable() {
                @Override
                public void run() {
                    while (true){
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        System.out.println(Thread.currentThread().getName()+"--"+sequence3.getValue());
                    }

                }
            }).start();



}
}
